package com.smcdd.cdb.dbo.cdb_dbo.ui.activity;

import android.support.v4.view.ViewPager;
import android.widget.ImageView;
import android.widget.TextView;

import com.smcdd.cdb.dbo.cdb_dbo.R;
import com.smcdd.cdb.dbo.cdb_dbo.service.entity.DayShop;
import com.smcdd.cdb.dbo.cdb_dbo.service.presenter.DetailPresenter;
import com.smcdd.cdb.dbo.cdb_dbo.service.view.IDetail;
import com.smcdd.cdb.dbo.cdb_dbo.ui.adapter.ShopPagerAdapter;
import com.smcdd.cdb.dbo.cdb_dbo.ui.base.BaseFragmentActivity;
import com.smcdd.cdb.dbo.cdb_dbo.ui.base.BaseFragmentFragment;
import com.smcdd.cdb.dbo.cdb_dbo.ui.fragment.FragmentFactory;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

/**
 * 作者：Administrator on 2017/7/6 12:51
 * 邮箱：zhanghuaiha@gmail.com
 * 今日达标店铺
 */

public class DetailActivity extends BaseFragmentActivity<IDetail,DetailPresenter> implements IDetail {
    private ImageView reach_back;
    private TextView reach_yet,reach_not;
    private ViewPager reach_vp;
    private List<BaseFragmentFragment> mFragmentList = new ArrayList<>();


    @Override
    public void initView() {
        reach_back = (ImageView) findViewById(R.id.reach_back);
        reach_yet = (TextView) findViewById(R.id.reach_yet);
        reach_not = (TextView) findViewById(R.id.reach_not);
        reach_vp = (ViewPager) findViewById(R.id.reach_vp);
    }

    @Override
    public void initData() {
        mFragmentList.add(FragmentFactory.getInstance().getReachYetFragment());
        mFragmentList.add(FragmentFactory.getInstance().getReachNotFragment());
        reach_vp.setAdapter(new ShopPagerAdapter(this.getSupportFragmentManager(),mFragmentList));
        reach_yet.setSelected(true);
        mPresenter.loadContacts();
        mPresenter.getInfo();
    }


    @Override
    public void onDestroy() {
        super.onDestroy();
        mFragmentList.clear();
    }


    @Override
    public void initListener() {
        reach_back.setOnClickListener(v -> finish());
        reach_yet.setOnClickListener(v -> reach_vp.setCurrentItem(0));
        reach_not.setOnClickListener(v -> reach_vp.setCurrentItem(1));
        reach_vp.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                switch (position) {
                    case 0:
                        reach_yet.setSelected(true);
                        reach_not.setSelected(false);
                        break;
                    case 1:
                        reach_yet.setSelected(false);
                        reach_not.setSelected(true);
                        break;
                    default:
                        break;
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    @Override
    protected DetailPresenter createPresenter() {
        return new DetailPresenter(this);
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.activity_detail;
    }
}
